//
//  EasyTipAppDelegate.m
//  EasyTip
//
//  Created by Jeffrey Palm on 2/14/09.
//  Copyright Jeffrey Palm 2009. All rights reserved.
//

#import "EasyTipAppDelegate.h"
#import "RootViewController.h"
#import "Category.h"
#import "Criteria.h"

@implementation EasyTipAppDelegate

static EasyTipAppDelegate *instance;

@synthesize window;
@synthesize navigationController;
@synthesize currentPacket;

+ (EasyTipAppDelegate*)getInstance {
	return instance;
}

- (id)init {
	if (self = [super init]) {
		instance = self;
		categories2criterias = [[NSMutableDictionary alloc] init];
	}
	return self;
}

- (void)accumulate:(Category*)cat criterion:(Criteria*)crit {
	[categories2criterias setObject:crit forKey:cat.name];
}

- (int)totalValue {
	NSArray *crits = [categories2criterias allValues];
	NSEnumerator *en = [crits objectEnumerator];
	Criteria *c;
	int total = 0;
	while (c = (Criteria*)[en nextObject]) {
		total += [c value];
	}
	return total;
}

- (NSArray*)criterias {
	return [categories2criterias allValues];
}


- (void)applicationDidFinishLaunching:(UIApplication *)application {
	
	// Configure and show the window
	[window addSubview:[navigationController view]];
	[window makeKeyAndVisible];
	
	// Have to give the root guy an actual Category
}


- (void)applicationWillTerminate:(UIApplication *)application {
	// Save data if appropriate
}


- (void)dealloc {
	[navigationController release];
	[window release];
	[categories2criterias release];
	[super dealloc];
}

@end
